<script type="text/javascript">
function SelectAllCheckboxes(chk) {
	$('#list_table >tbody >tr >td:nth-child(1)').find("input:checkbox").attr('checked', chk.checked);
}

</script>

<?=form_open('admin/users/index', 'id="form_users" name="form_users" class="main_cont border-top-none" method="post"'); ?>
<div class="acc_list_filter">
<table class="box_search">
	<tr>
		<td><span><?=lang('users_filter_keyword_label');?></span><br/> <?=form_input('keyword', $filter['keyword'], 'class="textbox" name="keyword"'); ?></td>
		<td><span><?=lang('users_filter_searh_on_label');?></span><br/> 
			<select id="search_on" class="inputbox" name="search_on">
				<? $selected = ''; if($filter['search_on'] == 'name') $selected = 'selected' ?>
				<option <?= $selected ?> value="name"><?=lang('user_name')?></option>
				<? $selected = ''; if($filter['search_on'] == 'email') $selected = 'selected' ?>
				<option <?= $selected ?> value="email"><?=lang('user_email')?></option>
			</select>
		</td>
		<td><span><?=lang('user_role_label');?></span><br/> 
			<select id="role" class="inputbox" name="role">
				<? $selected = ''; if($filter['role'] == '') $selected = 'selected' ?>
				<option <?= $selected ?> value="0"><?=lang('dropdown_all_item_label');?></option>
				<?php if ($roles):?>
					<?php foreach($roles as $role):?>
						<? $selected = ''; if($filter['role'] == $role->name) $selected = 'selected' ?>
						<option <?= $selected ?> value="<?php echo $role->name?>"><?php echo $role->name?></option>
					<?php endforeach;?>
				<?php endif;?>
			</select>
		</td>
		<td><input class="btn_admin" onclick="getParam();" type="submit" value="<?= lang('users_filter_search_btn') ?>" /></td>
	</tr>
	<tr>
		<td><span><?=lang('user_status_label');?></span><br/>
			<select id="is_active" class="inputbox" name="is_active">
				<? $selected = ''; if($filter['is_active'] == -1) $selected = 'selected' ?>
				<option <?= $selected ?> value="-1"><?=lang('dropdown_all_item_label');?></option>
				<? $selected = ''; if($filter['is_active'] == USER_STATUS_VERIFIED) $selected = 'selected' ?>
				<option <?= $selected ?> value="<?=USER_STATUS_VERIFIED?>"><?=lang('user_status_'.USER_STATUS_VERIFIED);?></option>				
				<? $selected = ''; if($filter['is_active'] == USER_STATUS_LOCKED) $selected = 'selected' ?>
				<option <?= $selected ?> value="<?=USER_STATUS_LOCKED?>"><?=lang('user_status_'.USER_STATUS_LOCKED);?></option>		
			</select>
		</td>			
		<td></td>
		<td></td>
		<td></td>
	</tr>
</table>
</div>
	<span class="filter_result">
		<strong><?php echo sprintf(lang('users_results_found_message'), $total);?></strong>
	</span>
	
<?php echo $toolbar;?>
	<table border="0" id="list_table" class="table table-striped table-bordered mediaTable activeMediaTable">
		<thead>
		<tr>
			<th class="first"><input type="checkbox" onclick="SelectAllCheckboxes(this);" value="" id="check_nav"/></th>			
			<th><a href="#"><?=lang('user_name_label');?></a></th>
			<th><a href="#"><?=lang('user_email_label');?></a></th>
			<th><a href="#"><?=lang('user_role_label');?></a></th>
			<th><a href="#"><?=lang('user_status_label');?></a></th>
			<th><a href="#"><?=lang('user_joined_label');?></a></th>
			<th><a href="#"><?=lang('user_last_visit_label');?></a></th>
		</tr>
		</thead>
		<tbody>
		<? if (!empty($users)): ?>
			<? $i = 0;
			foreach ($users as $member): 
			$i = 1-$i; ?>
				<tr class="row_<?= $i; ?>">
					<td><input type="checkbox" name="action_to[]" value="<?= $member->id; ?>" /></td>
					<td><?=anchor('admin/users/edit/' . $member->id, $member->name); ?></td>
					<td><?=$member->email; ?></td>
					<td><?=$member->role; ?></td>
					<td><?=lang('user_status_' . $member->is_active); ?></td>
					<td><?=date('M d, Y', $member->created_on); ?></td>
					<td><?=($member->last_login > 0 ? date('M d, Y', $member->last_login) : lang('user_never_label')); ?></td>
					</tr>
			<? endforeach; ?>
		<? else: ?>
			<tr>
				<td colspan="7"><?=lang('user_no_registred');?></td>
			</tr>
		<? endif; ?>
		</tbody>	
	</table>
<?=form_close(); ?>
